package com.hgh.wallet_demo.Controller;

import com.hgh.wallet_demo.Common.R;
import com.hgh.wallet_demo.Dto.Result;
import com.hgh.wallet_demo.Service.UserWalletDepositService;
import com.hgh.wallet_demo.Service.impl.UserWalletDepositServiceImpl;
import com.hgh.wallet_demo.vo.Cost_User;
import com.hgh.wallet_demo.vo.Wallet;
import com.hgh.wallet_demo.vo.deposit_User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Deposit")
public class UserWalletDepositEntity {
    @Autowired
    private UserWalletDepositService depositService;

    /**
     * 用户消费100元的接口
     * @param cost
     * @return
     */

    @PostMapping("/cost")
    public R cost(@RequestBody Cost_User cost){
        String info = String.valueOf(depositService.cost(cost));
        if(info.equals("余额不足")){
            return R.error("余额不足");
        }else {
            return R.ok();
        }

    }

    /**
     * 用户退款20元接口
     * @param deposit
     * @return
     */
    @PostMapping("/refund")
    public R refund(@RequestBody deposit_User deposit){
        depositService.refund(deposit);
        return R.ok();
    }


    /**
     * 查询用户钱包金额变动明细的接口
     * @param userId
     * @return
     */
    @RequestMapping("list")
    public R listbyUserId(@RequestParam("userId") Long userId){
        List<Wallet> list = depositService.listbyUserId(userId);
        return R.ok().put("list",list);
    }
}
